#define _CRT_SECURE_NO_WARNINGS	


char* replaceSpaces(char* S, int length)
{
    int count = 0;
    for (int i = 0; i < length; i++)
    {
        if (S[i] == ' ')
            count++;
    }
    int end = length + count * 2;
    S[end--] = '\0';
    length--;
    while (length >= 0)
    {
        if (S[length] != ' ')
        {
            S[end--] = S[length--];
        }
        else
        {
            S[end--] = '0';
            S[end--] = '2';
            S[end--] = '%';
            length--;
        }
    }
    return S;
}